package org.cfg;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Date;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import com.sojoys.artifact.build.data.base.BaseCfg;
import java.util.List;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import java.util.Map;
import org.interfaces.Refresher;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 商店配置
 */
public class StoreCfg extends BaseCfg<StoreCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "store";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.StoreCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 13;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"ID","商店类型","名称","货源：1:配置档  2：玩家商城","排序","开启条件类型","开启条件值","自动刷新表达式","刷新消耗ID","刷新消耗数量","展示货币类型","开启时间类型","开启时间值",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","storeType","name","commoditySupplyType","rank","openContType","openContVal","autoRefreshCorn","refreshCostId","refreshCostNum","showCurrency","openTimeType","openTime",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","storeType","name","commoditySupplyType","rank","openContType","openContVal","autoRefreshCorn","refreshCostId","refreshCostNum","showCurrency","openTimeType","openTime",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,1691984827,3373707,1444887510,3492908,1920494070,754689253,-1063811084,2056824963,-662930146,-276569554,410961937,-504645577,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","String","int","int","int","int","String","int[]","int[]","int[]","int","int[]",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,String.class,Integer.class,Integer.class,Integer.class,Integer.class,String.class,int[].class,int[].class,int[].class,Integer.class,int[].class,};
	
	/**
	 * ID
	 */
	private int id;
	
	/**
	 * 商店类型
	 */
	private int storeType;
	
	/**
	 * 名称
	 */
	private String name;
	
	/**
	 * 货源：1:配置档  2：玩家商城
	 */
	private int commoditySupplyType;
	
	/**
	 * 排序
	 */
	private int rank;
	
	/**
	 * 开启条件类型
	 */
	private int openContType;
	
	/**
	 * 开启条件值
	 */
	private int openContVal;
	
	/**
	 * 自动刷新表达式
	 */
	private String autoRefreshCorn;
	
	/**
	 * 刷新消耗ID
	 */
	private int[] refreshCostId;
	
	/**
	 * 刷新消耗数量
	 */
	private int[] refreshCostNum;
	
	/**
	 * 展示货币类型
	 */
	private int[] showCurrency;
	
	/**
	 * 开启时间类型
	 */
	private int openTimeType;
	
	/**
	 * 开启时间值
	 */
	private int[] openTime;
	
	
	
	public static StoreCfg builder() {
		StoreCfg storeCfg = new StoreCfg();
		return storeCfg;
	}
	
	/**
	 * ID
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 商店类型
	 */
	public int getStoreType() {
		return storeType;
	}
	
	/**
	 * 名称
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * 货源：1:配置档  2：玩家商城
	 */
	public int getCommoditySupplyType() {
		return commoditySupplyType;
	}
	
	/**
	 * 排序
	 */
	public int getRank() {
		return rank;
	}
	
	/**
	 * 开启条件类型
	 */
	public int getOpenContType() {
		return openContType;
	}
	
	/**
	 * 开启条件值
	 */
	public int getOpenContVal() {
		return openContVal;
	}
	
	/**
	 * 自动刷新表达式
	 */
	public String getAutoRefreshCorn() {
		return autoRefreshCorn;
	}
	
	/**
	 * 刷新消耗ID
	 */
	public int[] getRefreshCostId() {
		return refreshCostId;
	}
	
	/**
	 * 刷新消耗数量
	 */
	public int[] getRefreshCostNum() {
		return refreshCostNum;
	}
	
	/**
	 * 展示货币类型
	 */
	public int[] getShowCurrency() {
		return showCurrency;
	}
	
	/**
	 * 开启时间类型
	 */
	public int getOpenTimeType() {
		return openTimeType;
	}
	
	/**
	 * 开启时间值
	 */
	public int[] getOpenTime() {
		return openTime;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.storeType;
        values[2] = this.name;
        values[3] = this.commoditySupplyType;
        values[4] = this.rank;
        values[5] = this.openContType;
        values[6] = this.openContVal;
        values[7] = this.autoRefreshCorn;
        values[8] = this.refreshCostId;
        values[9] = this.refreshCostNum;
        values[10] = this.showCurrency;
        values[11] = this.openTimeType;
        values[12] = this.openTime;
        return values;
	}
	
	protected StoreCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.storeType = (int)vals[1];
		this.name = (String)vals[2];
		this.commoditySupplyType = (int)vals[3];
		this.rank = (int)vals[4];
		this.openContType = (int)vals[5];
		this.openContVal = (int)vals[6];
		this.autoRefreshCorn = (String)vals[7];
		this.refreshCostId = (int[])vals[8];
		this.refreshCostNum = (int[])vals[9];
		this.showCurrency = (int[])vals[10];
		this.openTimeType = (int)vals[11];
		this.openTime = (int[])vals[12];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.storeType);
        map.put(keys[2], this.name);
        map.put(keys[3], this.commoditySupplyType);
        map.put(keys[4], this.rank);
        map.put(keys[5], this.openContType);
        map.put(keys[6], this.openContVal);
        map.put(keys[7], this.autoRefreshCorn);
        map.put(keys[8], this.refreshCostId);
        map.put(keys[9], this.refreshCostNum);
        map.put(keys[10], this.showCurrency);
        map.put(keys[11], this.openTimeType);
        map.put(keys[12], this.openTime);
        return map;
    }
    
    protected StoreCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.storeType = (int)map.get(keys[1]);
   		this.name = (String)map.get(keys[2]);
   		this.commoditySupplyType = (int)map.get(keys[3]);
   		this.rank = (int)map.get(keys[4]);
   		this.openContType = (int)map.get(keys[5]);
   		this.openContVal = (int)map.get(keys[6]);
   		this.autoRefreshCorn = (String)map.get(keys[7]);
   		this.refreshCostId = (int[])map.get(keys[8]);
   		this.refreshCostNum = (int[])map.get(keys[9]);
   		this.showCurrency = (int[])map.get(keys[10]);
   		this.openTimeType = (int)map.get(keys[11]);
   		this.openTime = (int[])map.get(keys[12]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.storeType);
        obj.put(keys[2], this.name);
        obj.put(keys[3], this.commoditySupplyType);
        obj.put(keys[4], this.rank);
        obj.put(keys[5], this.openContType);
        obj.put(keys[6], this.openContVal);
        obj.put(keys[7], this.autoRefreshCorn);
        obj.put(keys[8], this.refreshCostId);
        obj.put(keys[9], this.refreshCostNum);
        obj.put(keys[10], this.showCurrency);
        obj.put(keys[11], this.openTimeType);
        obj.put(keys[12], this.openTime);
        return obj;
    }
    
    protected StoreCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.storeType = obj.getIntValue(keys[1]);
	    this.name = obj.getString(keys[2]);
	    this.commoditySupplyType = obj.getIntValue(keys[3]);
	    this.rank = obj.getIntValue(keys[4]);
	    this.openContType = obj.getIntValue(keys[5]);
	    this.openContVal = obj.getIntValue(keys[6]);
	    this.autoRefreshCorn = obj.getString(keys[7]);
		this.refreshCostId = obj.getObject(keys[8],int[].class);
		this.refreshCostNum = obj.getObject(keys[9],int[].class);
		this.showCurrency = obj.getObject(keys[10],int[].class);
	    this.openTimeType = obj.getIntValue(keys[11]);
		this.openTime = obj.getObject(keys[12],int[].class);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.storeType);
	    byteBuf.writeString(this.name);
	    byteBuf.writeInt(this.commoditySupplyType);
	    byteBuf.writeInt(this.rank);
	    byteBuf.writeInt(this.openContType);
	    byteBuf.writeInt(this.openContVal);
	    byteBuf.writeString(this.autoRefreshCorn);
	    byteBuf.writeObject(this.refreshCostId);
	    byteBuf.writeObject(this.refreshCostNum);
	    byteBuf.writeObject(this.showCurrency);
	    byteBuf.writeInt(this.openTimeType);
	    byteBuf.writeObject(this.openTime);
    }
	
	protected StoreCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.storeType = byteBuf.readInt(null);
	    this.name = byteBuf.readString(null);
	    this.commoditySupplyType = byteBuf.readInt(null);
	    this.rank = byteBuf.readInt(null);
	    this.openContType = byteBuf.readInt(null);
	    this.openContVal = byteBuf.readInt(null);
	    this.autoRefreshCorn = byteBuf.readString(null);
	    this.refreshCostId = byteBuf.readIntArray(null);
	    this.refreshCostNum = byteBuf.readIntArray(null);
	    this.showCurrency = byteBuf.readIntArray(null);
	    this.openTimeType = byteBuf.readInt(null);
	    this.openTime = byteBuf.readIntArray(null);
	    return this;
	}
	
	public StoreCfg deepCopy(){
		StoreCfg storeCfg = null;
		try {
			storeCfg = (StoreCfg) super.clone();
		    storeCfg.refreshCostId = ToolCopy.copyObject(this.refreshCostId);
		    storeCfg.refreshCostNum = ToolCopy.copyObject(this.refreshCostNum);
		    storeCfg.showCurrency = ToolCopy.copyObject(this.showCurrency);
		    storeCfg.openTime = ToolCopy.copyObject(this.openTime);
			return storeCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return storeCfg;
	}
//自定义内容起始位置
	private Date nextRefreshDate;
	private Date lastRefreshDate;



	public Date getNextRefreshDate() {
		return nextRefreshDate;
	}

	public void setNextRefreshDate(Date nextRefreshDate) {
		this.nextRefreshDate = nextRefreshDate;
	}

	public Date getLastRefreshDate() {
		return lastRefreshDate;
	}

	public void setLastRefreshDate(Date lastRefreshDate) {
		this.lastRefreshDate = lastRefreshDate;
	}

	public class StoreRefresher implements Refresher{
		@Override
		public Date getNextRefreshDate() {
			return nextRefreshDate;
		}

		@Override
		public void setNextRefreshDate(Date date) {
			nextRefreshDate = date;
		}

		@Override
		public Date getLastRefreshDate() {
			return lastRefreshDate;
		}

		@Override
		public void setLastRefreshDate(Date date) {
			lastRefreshDate = date;
		}
	}
//自定义内容结束位置
}
